/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;


import java.awt.Color;
import main.WinkelApplication;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import model.Product;
/**
 *
 * @author Jack Sierkstra
 */

public class Manage extends JPanel implements MouseListener, ActionListener {
    
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    
    GridLayout layout = new GridLayout(0,2);


    public Manage(int accesLevel) {
        super();
        
        
        setLayout(layout);
        
               
        initComponents(accesLevel);
    }

    private void initComponents(int accesLevel) {
        if(accesLevel==1){
            addTitle1();
            addTitle3();
            addTitle5();
        }
        if(accesLevel==2) {
            addTitle4();
            addTitle5();
        }
        
        if(accesLevel==3) {
            addTitle();
            addTitle1();
            addTitle2();
            addTitle3();
            addTitle4();
            addTitle5();
          
        }
    }

  
    private void addTitle() {
   
        ClassLoader cldr = this.getClass().getClassLoader();
        java.net.URL imageURL   = cldr.getResource("view/rapportage.png");
        ImageIcon icon = new ImageIcon(imageURL);
        
        JLabel lblTitle1 = new JLabel("Rapportage bekijken", icon, SwingConstants.CENTER);
        lblTitle1.setBounds(20, 20, (dim.width/5) , dim.height/12);
        
        lblTitle1.setFont(WinkelApplication.getInstance().computeFontSize(1));
        lblTitle1.setName("0");
        lblTitle1.addMouseListener(this);
        
        add(lblTitle1);
    }
    
    private void addTitle1() {
   
        ClassLoader cldr = this.getClass().getClassLoader();
        java.net.URL imageURL   = cldr.getResource("view/order.png");
        ImageIcon icon = new ImageIcon(imageURL);
        
        JLabel lblTitle1 = new JLabel("Order beheren", icon, SwingConstants.CENTER);
        
        lblTitle1.setBounds(20, 20, (dim.width/5) , dim.height/12);
        
        lblTitle1.setFont(WinkelApplication.getInstance().computeFontSize(1));
        lblTitle1.setName("1");
        lblTitle1.addMouseListener(this);
        
        add(lblTitle1);
    }   
    
    private void addTitle2() {
   
        ClassLoader cldr = this.getClass().getClassLoader();
        java.net.URL imageURL   = cldr.getResource("view/gebruiker.png");
        ImageIcon icon = new ImageIcon(imageURL);
        
        JLabel lblTitle1 = new JLabel("Gebruiker beheren", icon, SwingConstants.CENTER);
        
        lblTitle1.setBounds(20, 20, (dim.width/5) , dim.height/12);
        
        lblTitle1.setFont(WinkelApplication.getInstance().computeFontSize(1));
        lblTitle1.setName("2");
        lblTitle1.addMouseListener(this);
        
        add(lblTitle1);
    }
    
    private void addTitle3() {
   
        ClassLoader cldr = this.getClass().getClassLoader();
        java.net.URL imageURL   = cldr.getResource("view/klant.png");
        ImageIcon icon = new ImageIcon(imageURL);
        
        JLabel lblTitle1 = new JLabel("Klant beheren", icon, SwingConstants.CENTER);
        
        lblTitle1.setBounds(20, 20, (dim.width/5) , dim.height/12);
        
        lblTitle1.setFont(WinkelApplication.getInstance().computeFontSize(1));
        lblTitle1.setName("3");
        lblTitle1.addMouseListener(this);
        
        add(lblTitle1);
    }
    
    
     private void addTitle4() {
   
        ClassLoader cldr = this.getClass().getClassLoader();
        java.net.URL imageURL   = cldr.getResource("view/voorraad.png");
        ImageIcon icon = new ImageIcon(imageURL);
        
        JLabel lblTitle1 = new JLabel("Voorraad beheren", icon, SwingConstants.CENTER);
        
        lblTitle1.setBounds(20, 20, (dim.width/5) , dim.height/12);
        
        lblTitle1.setFont(WinkelApplication.getInstance().computeFontSize(1));
        lblTitle1.setName("4");
        lblTitle1.addMouseListener(this);
        
        add(lblTitle1);
    }
     
      private void addTitle5() {
   
        ClassLoader cldr = this.getClass().getClassLoader();
        java.net.URL imageURL   = cldr.getResource("view/x.png");
        ImageIcon icon = new ImageIcon(imageURL);
        
        JLabel lblTitle1 = new JLabel("Verlaat dit menu", icon, SwingConstants.CENTER);
        
        lblTitle1.setBounds(20, 20, (dim.width/5) , dim.height/12);
        
        lblTitle1.setFont(WinkelApplication.computeFontSize(1));
        lblTitle1.setName("5");
        lblTitle1.addMouseListener(this);
        
        add(lblTitle1);
    }

     
    @Override
    public void mouseClicked(MouseEvent event) {
        JLabel label = (JLabel) event.getSource();
        if (label.getName().equals("0")) {
            WinkelApplication.getInstance().showPanel(new view.report.ReportPanel());
        } else if (label.getName().equals("1")) {
            WinkelApplication.getInstance().showPanel(new view.order.OrderPanel());
        } else if (label.getName().equals("2")) {
            WinkelApplication.getInstance().showPanel(new view.UserPanel());
        } else if (label.getName().equals("3")) {
            WinkelApplication.getInstance().showPanel(new view.CustomerPanel());
        } else if (label.getName().equals("4")) {
            WinkelApplication.getInstance().showPanel(new view.supply.SupplyPanel());
        } else if (label.getName().equals("5")) {
            WinkelApplication.getInstance().showPanel(new view.CategoryList());
        }
    }

    @Override
    public void mouseEntered(MouseEvent event) {
        JLabel label = (JLabel) event.getSource();
        label.setBackground(new Color(151, 186, 225));
        label.setForeground(Color.blue);
    }

    @Override
    public void mousePressed(MouseEvent event) {
        // Intentionally left blank.
    }

    @Override
    public void mouseReleased(MouseEvent event) {
        // Intentionally left blank.
    }

    @Override
    public void mouseExited(MouseEvent event) {
        JLabel label = (JLabel) event.getSource();
        label.setBackground(new Color(151, 186, 225));
        label.setForeground(Color.black);
    }

    @Override
    public void actionPerformed(ActionEvent event) {
        JButton label = (JButton) event.getSource();
        if (label.getName().equals("1")) {
            WinkelApplication.getInstance().showPanel(new view.CategoryList());
        } else {
            String product_id = ((JButton) event.getSource()).getName();
            Product product = WinkelApplication.getQueryManager().getProduct(Integer.parseInt(product_id));
            WinkelApplication.getBasket().addProduct(product);
        }
    }

    @Override
    public void paint(Graphics graphics) {
        super.paint(graphics);
        //graphics.drawLine(20, 45, 540, 45);
    }
}

    

